package com.dao.impl;

import com.dao.CommunityDao;
import com.entity.household_location;
import com.util.DBconn;

import java.sql.ResultSet;
import java.sql.SQLException;

public class CommunityDaoImpl implements CommunityDao {
    public boolean add(household_location location){
        boolean flag = false;
        DBconn.init();
        int i = DBconn.addUpdDel("insert into household_location(ID,CommunityID,BuildingID,ApartmentID,RoomID)" + "values('"+location.getID()+"','"+location.getCommunityID()+"','"+location.getBuildingID()+"','"+location.getApartmentID()+"','"+location.getRoomID()+"')");
        int j = DBconn.addUpdDel("insert into household_data(ID,Name,Sex,HomephoneNo,TelephoneNo,WorkUnit,WorkPhone,WorkAddress,CheckinTime)" + "values('"+location.getID()+"','"+location.getName()+"','"+location.getSex()+"','"+location.getHomephoneNo()+"','"+location.getTelephoneNo()+"','"+location.getWorkUnit()+"','"+location.getWorkPhone()+"','"+location.getWorkAddress()+"','"+location.getCheckinTime()+"')");
        if (i>0){
            if (j>0){
                flag = true;
            }
        }
        DBconn.closeConn();
        return flag;
    }

    @Override
    public int count() {
        int count = -1;
        try{
            DBconn.init();
            ResultSet rs = DBconn.selectSql("select count(*) from household_data");
            while(rs.next()){
                count = rs.getInt("count(*)");
            }
        } catch (SQLException e){
            e.printStackTrace();
        }
        return count;
    }
}
